//
//  STHairProsVC.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/11.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STHairProsVC.h"

#import "STShowColListView.h"
#import "YLNavTitleBigSmallLab.h"
#import "STProDetailVC.h"
#import "SWUploadHairProsViewController.h"
#import "SWHairProsModel.h"
#import "STProDetailVC.h"

@interface STHairProsVC ()<STShowColListViewDelegate>{
    STShowColListView * hairProView;
    UILabel * proTitleLab;
}
@property(nonatomic, strong) NSArray <SWHairProsModel *>*dataArray;
@end

@implementation STHairProsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self wr_setNavBarTintColor:[UIColor blackColor]];
    proTitleLab = [YLNavTitleBigSmallLab getNavigationBigAndSmallTitleWithString:@"我的作品(999)" smallFromLocation:4];
    
    self.navigationItem.titleView = proTitleLab;
    
    UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(uploadAction:)];
    self.navigationItem.rightBarButtonItem =rightBarBtn;
    [self loadProjectImgsView];
    [self getDataFromService];
}

-(void)loadProjectImgsView{
    hairProView=[[STShowColListView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    hairProView.delegate = self;
    float w = (SCREEN_WIDTH-(3*10+1)) / 2;
    float h =  w*1.3;
    hairProView.cellSize = CGSizeMake(w, h);
    hairProView.sectionInset = UIEdgeInsetsMake(10,10,10,10);
    hairProView.showViewClassName = @"STProDetailCell";
    [hairProView setShowCollectionViewWithData:@[@"",@"",@"",@""]];
    [self.view addSubview:hairProView];
}

#pragma mark - 请求网络
- (void)getDataFromService {
    
    BasicRequest * request = [[BasicRequest alloc] initWithParams:@{@"stylistId":[YLUserInfo sharedInstance].userID}];
    request.URL = [NSString stringWithFormat:@"%@%@",BASEURL, @"stylistOpus/getStylistOpusByStylistId"];
    request.requestMethod = HttpRequestMethodGET;
    [request startRequestWithSuccess:^(NSURLSessionTask *task, id responseObject) {
        NSNumber *code = responseObject[@"code"];
        if (code.integerValue == 200) {
            _dataArray = [NSArray modelArrayWithClass:[SWHairProsModel class] json:responseObject[@"data"]];
            [hairProView setShowCollectionViewWithData:_dataArray];
        }
    } Failure:nil];
}

-(void)showColListSelRow:(NSIndexPath *)row{
    STProDetailVC* prosVC  =[STProDetailVC new];
    prosVC.projectId = @"";
    prosVC.hidesBottomBarWhenPushed= YES;
    [self.navigationController pushViewController:prosVC animated:YES];

}

- (void)showColList:(STShowColListView *)view SelRow:(NSIndexPath *)row {
    
    STProDetailVC *viewController = [STProDetailVC new];
    viewController.projectId = self.dataArray[row.row].id;
    [self.navigationController pushViewController:viewController animated:YES];
}

- (void)uploadAction:(id)sender {
    SWUploadHairProsViewController *controller = [SWUploadHairProsViewController new];
    [self.navigationController pushViewController:controller animated:YES];
}

@end
